In [2]:
from IPython.display import Audio, display, HTML
import librosa
import matplotlib.pyplot as plt
import numpy as np
import os
In [3]:
RATE = 22050

def forever():
    """Generator for iterating over integers from 0 onwards."""
    i = 0
    while True:
        yield i
        i += 1
        
def plot_wave(ax, wave, title='', range=None):
    ax.set_title(title)
    if range is not None:
        ax.plot(wave[range[0]:range[1]])
    else:
        ax.plot(wave)

def plot_mel(ax, mel, title=''):
    ax.set_title(title)
    pos = ax.imshow(mel.transpose(), aspect='auto', cmap='coolwarm', interpolation='nearest', origin='lower')
    # fig.colorbar(pos, orientation='horizontal')
    
def show_wave_and_mel(wave, mel, title=''):
    fig, axes = plt.subplots(2, dpi=100, figsize=(10, 5))
    plot_wave(axes[0], wave, title)
    n_zoom = int(0.5 * RATE)
    mid = len(wave) // 2
    # plot_wave(axes[1], wave, 'Zoomed in', (mid - n_zoom // 2, mid + n_zoom // 2))
    plot_mel(axes[1], mel, 'Mel spectrogram')
    plt.subplots_adjust(hspace=0.3)
    plt.show()
    display(Audio(wave, rate=RATE))

gid = 0
def show_results(name, title):
    display(HTML('<h1>%s</h1>' % title))
    for i in forever():
        try:
            if i == 0:
                wave = librosa.core.load(os.path.join(name, name + '.wav'))[0]
            else:
                wave = np.load(os.path.join(name, 'wave-%.5d.npy' % i))
            mel = np.load(os.path.join(name, 'mel-%.5d.npy' % i))
        except FileNotFoundError:
            break
        if i == 0:
            title = 'Original audio'
        else:
            title = ('Audio after %d WaveNet application' + ('' if i == 1 else 's')) % i
        show_wave_and_mel(wave, mel, title)
        
        global gid
        print('id: %d' % gid)
        gid += 1
        display(HTML('<hr style="height: 2px;">'))
In [4]:
show_results('chords', 'Chords')
show_results('tron', 'Speech from movie trailer')

Chords

Your browser does not support the audio element.
id: 0

Your browser does not support the audio element.
id: 1

Your browser does not support the audio element.
id: 2

Your browser does not support the audio element.
id: 3

Your browser does not support the audio element.
id: 4

Your browser does not support the audio element.
id: 5

Your browser does not support the audio element.
id: 6

Your browser does not support the audio element.
id: 7

Your browser does not support the audio element.
id: 8

Your browser does not support the audio element.
id: 9

Your browser does not support the audio element.
id: 10

Your browser does not support the audio element.
id: 11

Your browser does not support the audio element.
id: 12

Your browser does not support the audio element.
id: 13

Your browser does not support the audio element.
id: 14

Your browser does not support the audio element.
id: 15

Your browser does not support the audio element.
id: 16

Your browser does not support the audio element.
id: 17

Your browser does not support the audio element.
id: 18

Your browser does not support the audio element.
id: 19

Your browser does not support the audio element.
id: 20

Your browser does not support the audio element.
id: 21

Your browser does not support the audio element.
id: 22

Your browser does not support the audio element.
id: 23

Your browser does not support the audio element.
id: 24

Your browser does not support the audio element.
id: 25

Speech from movie trailer

Your browser does not support the audio element.
id: 26

Your browser does not support the audio element.
id: 27

Your browser does not support the audio element.
id: 28

Your browser does not support the audio element.
id: 29

Your browser does not support the audio element.
id: 30

Your browser does not support the audio element.
id: 31

Your browser does not support the audio element.
id: 32

Your browser does not support the audio element.
id: 33

Your browser does not support the audio element.
id: 34

Your browser does not support the audio element.
id: 35

Your browser does not support the audio element.
id: 36

Your browser does not support the audio element.
id: 37

Your browser does not support the audio element.
id: 38

Your browser does not support the audio element.
id: 39

Your browser does not support the audio element.
id: 40

Your browser does not support the audio element.
id: 41

Your browser does not support the audio element.
id: 42

Your browser does not support the audio element.
id: 43

Your browser does not support the audio element.
id: 44

Your browser does not support the audio element.
id: 45

Your browser does not support the audio element.
id: 46

Your browser does not support the audio element.
id: 47

Your browser does not support the audio element.
id: 48

Your browser does not support the audio element.
id: 49

Your browser does not support the audio element.
id: 50

Your browser does not support the audio element.
id: 51

Your browser does not support the audio element.
id: 52

Your browser does not support the audio element.
id: 53

Your browser does not support the audio element.
id: 54

Your browser does not support the audio element.
id: 55

Your browser does not support the audio element.
id: 56

Your browser does not support the audio element.
id: 57

Your browser does not support the audio element.
id: 58

Your browser does not support the audio element.
id: 59

Your browser does not support the audio element.
id: 60

Your browser does not support the audio element.
id: 61

Your browser does not support the audio element.
id: 62

Your browser does not support the audio element.
id: 63

Your browser does not support the audio element.
id: 64

Your browser does not support the audio element.
id: 65

Your browser does not support the audio element.
id: 66

Your browser does not support the audio element.
id: 67

Your browser does not support the audio element.
id: 68

Your browser does not support the audio element.
id: 69

Your browser does not support the audio element.
id: 70

Your browser does not support the audio element.
id: 71

Your browser does not support the audio element.
id: 72

Your browser does not support the audio element.
id: 73

Your browser does not support the audio element.
id: 74

In [ ]: